﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Prsrp
{
    /// <summary>
    /// Base class for any character or ai in the game.
    /// </summary>
    public class BaseCharacter : BaseAsset
    {
        #region Properties

        // Heal Points
        public int miHP;
        public int miMaxHP;

        #endregion

        #region Utility Functions

        public bool IsDead()
        {
            return miHP <= 0;
        }

        #endregion

        #region States Functions

        public enum BaseCharacterStates
        {
            kIdle = BaseStates.kEnd,
            kFalling,
            kEnd
        }

        /// <summary>
        ///  Basic function for falling characters.
        /// </summary>
        public virtual void OnFalling()
        {
            mbAffectedByGravity = true;
            // Fake Collision Detection
            if (mvPos.Y < 0)
            {
                mvSpeed.X = 0;
                mvSpeed.Y = 0;
                mvPos.Y = 0;
            }
            float fFloorLevel = GameGlobals.GameHeight - (mvSize.Y / 2.0f * mfScale) - 1;
            if (mvPos.Y > fFloorLevel)
            {
                mvPos.Y = fFloorLevel;
                mvSpeed.Y = 0;

                SetState(BaseCharacterStates.kIdle);
                mbAffectedByGravity = false;
            }
        }

        public override void OnInit()
        {
            SetState(BaseCharacterStates.kFalling);
        }

        #endregion

        /// <summary>
        /// This method should be updated in each BaseCharacter children.
        /// </summary>
        public virtual void LoadStates()
        {
            base.LoadStates();
            DefineState(BaseCharacterStates.kIdle, OnIdle);
            DefineState(BaseCharacterStates.kFalling, OnFalling);
        }
    }
}
